#include <iostream>
using namespace std;

int main()
{
        long a, b, p;
        cin >> a >> b >> p;

        cout << a << '^' << b << " mod " << p << '=';
        int ans = 1;
        while(b){
                if(b & 1){
                        ans = (ans * a)%p;
                }
                a = (a * a)%p;
                b >>= 1;
        }
        cout << ans << '\n';
        return 0;
}